<%--
  Created by IntelliJ IDEA.
  User: 栋
  Date: 2022/11/27
  Time: 9:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>商品信息</title>
    <script>
        function buy(){
            var itemInfor_method=document.getElementById("itemInfor_method").innerText;
            var cnt=document.getElementById("itemInfor_buyCount").value;
            if(Number(cnt)==0)
            {
                alert("购买数量不能为0");
                return ;
            }
            if(Number(cnt)>Number(document.getElementById("itemInfor_buyCount").max)) {
                alert("商品数量不足");
                return;
            }else if(itemInfor_method=="配送"){
                var address=document.getElementById("itemInfor_Address").value
                if(address==""){
                    alert("地址不能为空");
                    return;
                }
            }

            var pay = document.querySelector('.pay');
            var mask = document.querySelector('.pay-bg');
            mask.style.display = 'block';
            pay.style.display = 'block';
            var price=document.getElementById("itemInfor_price").innerText;
            var count=document.getElementById("itemInfor_buyCount").value;
            var title="共需"+price*count.toString()+"元";
            document.getElementById("need").textContent=title;


        }
        function closeZhiFu(){
            var pay = document.querySelector('.pay');
            var mask = document.querySelector('.pay-bg');
            mask.style.display = 'none';
            pay.style.display = 'none';
        }

        function pay(){
            var r=confirm("是否确认付款");
            if(r==true){
                var item_id=document.getElementById("itemInfor_id").innerText
                var itemInfor_name=document.getElementById("itemInfor_name").innerText
                var price=document.getElementById("itemInfor_price").innerText
                var count=document.getElementById("itemInfor_buyCount").value
                var itemInfor_method=document.getElementById("itemInfor_method").innerText
                if(itemInfor_method=="配送"){
                    var address=document.getElementById("itemInfor_Address").value
                    var itemInfor_Address="配送"+address
                }else{
                    var itemInfor_Address=itemInfor_method
                }
                var credit_pwd=document.getElementById("password").value;
                window.location.href="userServlet?action=buyItems&item_id="+item_id+"&itemInfor_name="+itemInfor_name+"&price="+price+"&count="+count+"&itemInfor_method="+itemInfor_method+"&itemInfor_Address="+itemInfor_Address+"&credit_pwd="+credit_pwd;

            }
        }
        function addToCar(){
            var item_id=document.getElementById("itemInfor_id").innerText
            var itemInfor_name=document.getElementById("itemInfor_name").innerText
            var price=document.getElementById("itemInfor_price").innerText
            var count=document.getElementById("itemInfor_buyCount").value
            if(Number(count)==0) {
                alert("数量不能为0");
                return ;
            }
            if(Number(count)>Number(document.getElementById("itemInfor_buyCount").max)){
                alert("商品数量不足");
                return;
            }

            var itemInfor_method=document.getElementById("itemInfor_method").innerText
            if(itemInfor_method=="配送"){
                var address=document.getElementById("itemInfor_Address").value
                var itemInfor_Address="配送"+address
            }else{
                var itemInfor_Address=itemInfor_method
            }
            window.location.href="userServlet?action=addToCar&item_id="+item_id+"&itemInfor_name="+itemInfor_name+"&price="+price+"&count="+count+"&itemInfor_method="+itemInfor_method+"&itemInfor_Address="+itemInfor_Address;

        }
    </script>
    <%@include file="/pages/base/base.jsp"%>
</head>
<body>
    <div class="container">
        <div class="itemInforContent">
            <div class="img_left">
                <img src="${i.item_img}" width="100%" height="320">
            </div>
            <div class="itemInfor_main">
                <div class="main">
                    <div >
                        <span class="propertyType">商品编号</span>
                        <div class="value" id="itemInfor_id">${i.item_id}</div>
                    </div>
                    <div >
                        <span class="propertyType">商品名称</span>
                        <div class="value" id="itemInfor_name">${i.item_name}</div>
                    </div>
                    <div >
                        <span class="propertyType">价格</span>
                        <div class="value" >￥<span id="itemInfor_price">${i.item_price}</span></div>
                    </div>
                    <div >
                        <span class="propertyType">卖家编号</span>
                        <div class="value" id="itemInfor_owerid">${i.ower_id}</div>
                    </div>
                    <div >
                        <span class="propertyType">商品介绍</span>
                        <div class="value" id="itemInfor_introduce">${i.item_introduce}</div>
                    </div>
                    <div >
                        <span class="propertyType">上架日期</span>
                        <div class="value" id="itemInfor_date">${i.audit_date}</div>
                    </div>
                    <div >
                        <span class="propertyType">购买数量</span>
                        <div class="value">
                            <input type="number" id="itemInfor_buyCount" value="0"title="请选择购买数量" min="0" max="${i.item_count}">
                        </div>
                    </div>
                    <div >
                        <span class="propertyType">交易方式</span>
                        <div class="value" id="itemInfor_method">${i.method}</div>
                        <c:set var="m" scope="session" value="${i.method}"/>
                    </div>
                    <c:if test="${m=='配送'}">
                        <div >
                            <span class="propertyType">收货地址</span>
                            <div class="value">
                                <input type="text" id="itemInfor_Address" value="${user.address}"title="请填写收货地址">
                            </div>
                        </div>
                    </c:if>

                </div>
                <div class="button">
                    <div><button onclick="buy()" >购买</button></div>
                    <div><button onclick="addToCar()">加入购物车</button></div>
                </div>
            </div>
            <div class="errorMsg">
                ${requestScope.msg}
            </div>
        </div>
        <div id="pay" class="pay">
            <div id="title" class="pay-title">银行卡密码
                <span><a id="closeBtn" href="javascript:void(0);" class="close-pay" onclick="closeZhiFu()">关闭</a></span>
            </div>
            <div id="need" style="text-align: center">

            </div>
            <div class="pay-input-content">
                <div class="pay-input">
                    <label>支付密码：</label>
                    <input type="password" placeholder="请输入银行卡密码" name="info[password]" id="password" class="list-input">
                </div>
            </div>
            <div id="pay_btn" class="pay_btn"><a href="javascript:void(0);" id="button-submit" onclick="pay()">提交</a></div>
        </div>
        <!-- 遮盖层 -->
        <div id="bg" class="pay-bg"></div>
    </div>
</body>
</html>
